package com.easyj.admin.activiti.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.easyj.admin.activiti.service.ProcessInstService;
import com.easyj.admin.activiti.service.TaskCommentService;
import com.easyj.admin.activiti.vo.ProcessInstQO;
import com.easyj.admin.activiti.vo.ProcessInstVO;
import com.easyj.base.common.ajax.Result;
import com.easyj.base.common.page.Page;
import com.easyj.base.controller.BaseController;


/**
 * 查询本人发起的流程实例
 * @author hjf
 *
 */
@RestController
@RequestMapping(value = "/processInst")
public class ProcessInstController extends BaseController{
	
	@Autowired
	private  ProcessInstService processInstService;
	
	@Autowired
	private TaskCommentService taskCommentService;
	
	
	@RequestMapping(value = "getCommentsByProcInstId", method = RequestMethod.GET)
    public Result getCommentsByProcInstId( @RequestParam(value = "procInstId")String procInstId) {
		return Result.Success(taskCommentService.findByProcInstId(procInstId));
	
	}
	
	@PostMapping(value = "findHistoryProcess")
	public Result findHistoryProcess(@RequestBody  ProcessInstQO filter) {
		filter.setStarter(this.getUserId().toString());
		Page<ProcessInstVO> page=processInstService.findHistoryProcess(filter);
		return Result.Success(page);
	}
	
	
	@PostMapping(value = "findRunningProcess")
	public Result findRunningProcess(@RequestBody  ProcessInstQO filter) {
		filter.setStarter(this.getUserId().toString());
		Page<ProcessInstVO> page=processInstService.findProcessInRunning(filter);
		return Result.Success(page);
	}
	
	@GetMapping(value = "getProcessInRunningCount")
	public Result getProcessInRunningCount() {
		ProcessInstQO filter =new ProcessInstQO();
		filter.setStarter(this.getUserId().toString());
		long count=processInstService.getProcessInRunningCount(filter);
		return Result.Success(count);
	}
	
	@GetMapping(value = "getHistoryProcessCount")
	public Result getHistoryProcessCount() {
		ProcessInstQO filter =new ProcessInstQO();
		filter.setStarter(this.getUserId().toString());
		long count=processInstService.getHistoryProcessCount(filter);
		return Result.Success(count);
	}

}
